﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Security;

namespace CoolCode.Web.UI.WebServices
{
    /// <summary>
    /// Summary description for UserService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [ScriptService]
    public class UserService : System.Web.Services.WebService
    {
        [WebMethod]
        [ScriptMethod]
        public IList<string> ListUsers(string prefixText, int count)
        {
            var users = string.IsNullOrEmpty(prefixText) ? Membership.GetAllUsers() : Membership.FindUsersByName(prefixText);
            List<string> list = new List<string>();
            foreach (MembershipUser user in users)
                list.Add(user.UserName);
            list.Sort();
            return list;
        }

        [WebMethod]
        [ScriptMethod]
        public IList<string> ListRoles(string prefixText, int count)
        {
            var list = Roles.GetAllRoles();
            return list;
        }
    }
}
